<?php
defined('IN_CMS') or exit('No permission resources.');
pc_base::load_app_class('admin','admin',0);
pc_base::load_sys_class('form','',0);
class roundimg extends admin  {
	function __construct() {
        parent::__construct();
		$this->db = pc_base::load_model("mybasecontent_model");
        $this->dbType = pc_base::load_model("myassorttype_model");
	}
	
	/**
	 * 列表
	 */
	function mylist(){
		$page = isset($_GET['page']) && intval($_GET['page']) ? intval($_GET['page']) : 1;
        
        $whereSql = " parent = 0";
        $assortTypeList = $this->dbType->select($whereSql);
        $assortTypeListKV = $this->setKVList($assortTypeList);
		switch ($_POST['action']){
            case "add":
                $item = $_POST['item'];
                $item['last_updated_time'] = $this->CURRENT_DATETIME;
                $item['created_time'] = $this->CURRENT_DATETIME;
                $id = $this->db->insert($item,true);
                break;
            case "edit":
                $id = $_POST['id'];
                $item = $_POST['item'];
                $item['last_updated_time'] = $this->CURRENT_DATETIME;
                $this->db->update($item,$where = 'id = '.$id);
                break;
        }
        
        $roundimgTpyeId = '';
        
        foreach($assortTypeList as $type){
            $typeId = $type['id'];
            $orderSql = " id DESC";
            $whereSql = array('assort_type_id'=>$typeId,'is_del'=>0);
            switch($type['name']){
                case 'roundimg':
                	$roundimgTpyeId = $typeId;
        			$lists = $this->db->listinfo($whereSql,$order = 'id DESC',$page);
                    break;
                default:break;
            }
        }
        $pages = $this->db->pages;
        
		include $this->admin_tpl('myroundimg_list');
	}
	
	
	function myadd(){
        $whereSql = " parent = 0";
        $assortTypeList = $this->dbType->select($whereSql);
		$typeId = $_GET['assort_type_id'];
		include $this->admin_tpl('myroundimg_add');
		
	}
	
	function myedit(){
        $whereSql = " parent = 0";
        $assortTypeList = $this->dbType->select($whereSql);
		$id = $_GET['id'];
		$whereSql = array('id'=>$id);
		$item = $this->db->get_one($whereSql);
		
		include $this->admin_tpl('myroundimg_edit');
	}

	function myview(){
		$id = $_GET['id'];
		$whereSql = "id = '" . $id . "'";
        $item = $this->db->get_one($whereSql);

		include $this->admin_tpl('myroundimg_view');
	}
	
	
	function mydelone(){
		$id = $_GET['id'];
		$new['is_del'] = 1;
		$this->db->update($new,$where = 'id = '.$id);
		$this->mylist();
	}
	
	/**
	 * 批量删除
	 */
	function mydel(){
		$ids = $_POST['id'];
		
		if(empty($ids) || !is_array($ids)){
			showmessage(L('没有记录可以删除'),HTTP_REFERER);
		}else{
			foreach ($ids as $id){
				$new['is_del'] = 1;
				$this->db->update($new,$where = 'id = '.$id);
			}
		}
		$this->mylist();
	}

	/**
	 * 审核
	 */
	function myCheck(){
		$ids = $_POST['id'];
	
		if(empty($ids) || !is_array($ids)){
			showmessage(L('没有记录可以删除'),HTTP_REFERER);
		}else{
			foreach ($ids as $id){
				$new['is_show'] = 1;
				$this->db->update($new,$where = 'id = '.$id);
			}
		}
		$this->mylist();
	}
	
	private function setKVList($lists){
		$kvList = array();
		foreach ($lists as $item){
			$kvList[$item['id']]=$item['name'];
		}
		return $kvList;
	}
	
}

?>